package com.gxz.shardingreadwrite.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class UserService {

    @Autowired(required = false)
    private JdbcTemplate jdbcTemplate;

    public void insert(String name) {
        String sql = "insert into t_user(name)  values (?)";
        jdbcTemplate.update(sql, name);
        List<String> list = this.jdbcTemplate.queryForList("select name from t_user", String.class);
        System.out.println(list);
    }

    public void getByMaster(long id) {
        String sql = "select name from t_user where id=?";
        List<String> list = this.jdbcTemplate.queryForList(sql, String.class, id);
        System.out.println(list);
    }

    public void getBySlave(long id) {
        String sql = "select name from t_user where id=?";
        List<String> list = this.jdbcTemplate.queryForList(sql, String.class, id);
        System.out.println(list);
    }

}